//
//  UIImageResizing.m
//  FunnyOfTheDay
//
//  Created by Giorgi Gioshvili on 12/2/10.
//  Copyright 2010 FSS. All rights reserved.
//

#import "UIImageResizing.h"

@implementation UIImage (Resize)

- (UIImage*)scaleToSize:(CGSize)size:(double)ratio {

	//Swap width and height flags depending on the image orientation (when it was shot)
	if ( self.imageOrientation == UIImageOrientationLeft || self.imageOrientation == UIImageOrientationRight ) {
		CGFloat tmp = size.width;
		size.width = size.height;
		size.height = tmp;
	}
		
	UIGraphicsBeginImageContext(size);
	
	CGContextRef context = UIGraphicsGetCurrentContext();
	CGContextTranslateCTM(context, 0.0, size.height);
	CGContextScaleCTM(context, 1.0, -1.0);
	
	CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), self.CGImage);
	
	UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
	
	UIGraphicsEndImageContext();
	
	return scaledImage;
}

@end